/*
 * Settings.java
 *
 * Created on 27 Март 2008 г., 17:50
 */

package my.engine.client.forms.settings;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import my.engine.client.ws.settings.Property;
import my.engine.client.ws.settings.SettingsService;
import my.engine.client.ws.settings.SettingsServiceService;
import my.engine.client.forms.settings.SettingEditForm;

/**
 *
 * @author  emikolenko
 */
public class SettingsForm extends javax.swing.JPanel {
    
    /** Creates new form Settings */
    public SettingsForm() {
        initComponents();
        customInitComponents();
        performDataPasting();
    }
    
    private void customInitComponents() {
        table.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() > 1) {
                    settingEditForm.setVisible(true);
                }
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

            public void mouseEntered(MouseEvent e) {
            }

            public void mouseExited(MouseEvent e) {
            }
            
        });
    }
    
    private void performDataPasting() {
        SettingsServiceService service = new SettingsServiceService();
        SettingsService port = service.getSettingsServicePort();
        List<Property> properties = port.getPortalPrefs();
        
        for (Property p : properties) {
            ((DefaultTableModel)table.getModel()).addRow(new String[]{p.getName(), p.getValue(), p.getDescription()});
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        settingsTable = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();

        jLabel1.setText("Portal Settings:");

        table.setAutoCreateRowSorter(true);
        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Value", "Description"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        settingsTable.setViewportView(table);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(settingsTable, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(settingsTable, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane settingsTable;
    private javax.swing.JTable table;
    // End of variables declaration//GEN-END:variables
    
    private SettingEditForm settingEditForm = new SettingEditForm();
}
